package com.graden.background.controller.sysrole;


import com.github.pagehelper.PageInfo;
import com.graden.background.common.conf.aop.operation.OperationAnnotation;
import com.graden.background.common.enums.OperationEnum;
import com.graden.background.common.enums.ResultEnum;
import com.graden.background.common.utils.apiresult.AbstractApiResult;
import com.graden.background.controller.sysrole.vo.RoleActivateVO;
import com.graden.background.controller.sysrole.vo.RoleAddVO;
import com.graden.background.controller.sysrole.vo.RoleSelectVO;
import com.graden.background.controller.sysrole.vo.RoleUpdateVO;
import com.graden.background.repository.sysrole.entity.SysRole;
import com.graden.background.service.sysrole.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 系统角色前端控制器
 * </p>
 *
 * @author zjf
 * @since 2019-03-21
 */
@RestController
@RequestMapping("/role")
@Api(tags = {"系统角色"})
public class SysRoleController {

	@Resource
	ISysRoleService iSysRoleService;

	@PostMapping("/page/{pageNo}/{pageSize}")
	@OperationAnnotation(operation = OperationEnum.SYSTEM_ROLE_SEE)
	public AbstractApiResult getPage(@PathVariable int pageNo, @PathVariable int pageSize, @RequestBody RoleSelectVO roleSelectVO) {

		PageInfo iPage = iSysRoleService.getAllByPage(pageNo, pageSize, roleSelectVO);

		return AbstractApiResult.success(iPage);
	}

	@GetMapping("/get")
	@ApiOperation(value = "查询角色列表(全部)接口")
	public AbstractApiResult getAll() {

		List<SysRole> sysRoles = iSysRoleService.getAll();

		return AbstractApiResult.success(sysRoles);
	}

	@GetMapping("/get/info/{id}")
	@ApiOperation(value = "查询详情接口")
	public AbstractApiResult getInfo(@PathVariable Integer id) {

		return AbstractApiResult.success(iSysRoleService.getInfo(id));
	}

	@PostMapping("/add")
	@ApiOperation(value = "角色添加接口")
	@OperationAnnotation(operation = OperationEnum.SYSTEM_ROLE_ADD)
	public AbstractApiResult addRole(@RequestBody RoleAddVO roleAddVO) {

		iSysRoleService.addRole(roleAddVO);

		return AbstractApiResult.success(ResultEnum.SUCCESS.getValue());
	}

	@PostMapping("/update")
	@ApiOperation(value = "角色修改接口")
	@OperationAnnotation(operation = OperationEnum.SYSTEM_ROLE_EDIT)
	public AbstractApiResult updateRole(@RequestBody RoleUpdateVO userUpdateVO) {

		iSysRoleService.updateRole(userUpdateVO);

		return AbstractApiResult.success(ResultEnum.SUCCESS.getValue());
	}

	@PostMapping("/activate")
	@ApiOperation(value = "角色激活/禁用接口")
	public AbstractApiResult activateRole(@RequestBody RoleActivateVO roleActivateVO) {

		iSysRoleService.activateRole(roleActivateVO);

		return AbstractApiResult.success(ResultEnum.SUCCESS.getValue());
	}

	@DeleteMapping("/delete/{id}")
	@ApiOperation(value = "角色删除接口")
	@OperationAnnotation(operation = OperationEnum.SYSTEM_ROLE_DELETE)
	public AbstractApiResult deleteRole(@PathVariable int id) {

		iSysRoleService.deleteRole(id);

		return AbstractApiResult.success(ResultEnum.SUCCESS.getValue());
	}

}
